package etr.bk.gui;

import etr.bk.gui.rpan.*;
import etr.bk.gui.lpan.*;
import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

import org.h2.jdbc.JdbcSQLException;

public class Frame extends JFrame
{
	private MainListener mListener;
	
	
	public Frame()
	{
		super("Book");
		
		System.out.println("Frame Start");
		
		//************  SET NIMBUS LOOK & FEEL *********************
		
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (UnsupportedLookAndFeelException e) {
		    // handle exception
		} catch (ClassNotFoundException e) {
		    // handle exception
		} catch (InstantiationException e) {
		    // handle exception
		} catch (IllegalAccessException e) {
		    // handle exception
		}
		
		//************Image VIEW frame************************************
		
		ImageViewFrame imageViewFrame = new ImageViewFrame();
		
		//****************************************************************
		//-----------Main Listener----------------------------------------
		
		this.mListener = MainListener.getListener();
		this.mListener.setParetn(this);
		
		this.addWindowListener(mListener);
		
		this.mListener.setImageViewFrame(imageViewFrame);
		
		//----------------------------------------------------------------
		
		//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setBounds(200, 200, 800, 600);
		this.setResizable(false);
		
		//---------------CPanel----------------------
		
		CPanel cPanel = new CPanel();
		this.add(cPanel,BorderLayout.CENTER);
		
		//-----------MENU----------------------------
		JMenuBar menuBar = new JMenuBar();
		JMenu menuFile = new JMenu("File    ");
		JMenu menuEdit = new JMenu("Edit     ");
		JMenu menuAbout = new JMenu("About");
		JMenuItem menuItemUnload = new JMenuItem("Unload Images");

		JMenuItem menuItemExit = new JMenuItem("Exit");
		
		JMenuItem menuItemPropSet = new JMenuItem("Set Default Image");
		JMenuItem menuItemPropReset = new JMenuItem("Reset Default Image");
		
		JMenuItem menuItemHelp = new JMenuItem("Help");
		
		menuFile.add(menuItemUnload);
		menuFile.addSeparator();
		menuFile.add(menuItemExit);
		
		menuEdit.add(menuItemPropSet);
		menuEdit.add(menuItemPropReset);
		
		menuAbout.add(menuItemHelp);
		menuBar.add(menuFile);
		menuBar.add(menuEdit);
		menuBar.add(menuAbout);
		
		menuBar.setBorder(BorderFactory.createRaisedBevelBorder());
		
		this.add(menuBar, BorderLayout.NORTH);
		//-------------------END MENU----------------
		
		
		mListener.setMenuItemPropSet(menuItemPropSet);
		mListener.setMenuItemPropReset(menuItemPropReset);
		mListener.setMenuItemUnload(menuItemUnload);
		mListener.setMenuItemExit(menuItemExit);
		mListener.setMenuItemHelp(menuItemHelp);
		
		menuItemExit.addActionListener(mListener);
		menuItemHelp.addActionListener(mListener);
		menuItemPropSet.addActionListener(mListener);
		menuItemPropReset.addActionListener(mListener);
		menuItemUnload.addActionListener(mListener);
		
		
	}
}

